package net.phoenix.repository.query.qom2;

/**
 * <code>AbstractQOMNode</code>...
 */
public abstract class AbstractQOMNode {

	protected final NamePathResolver resolver;

	public AbstractQOMNode(NamePathResolver resolver) {
		this.resolver = resolver;
	}

	/**
	 * Accepts a <code>visitor</code> and calls the appropriate visit method
	 * depending on the type of this QOM node.
	 * 
	 * @param visitor
	 *            the visitor.
	 * @param data
	 *            user defined data, which is passed to the visit method.
	 */
	public abstract Object accept(QOMTreeVisitor visitor, Object data) throws Exception;

	protected String quote(String path) {
		String str = (path);
		if (str.indexOf(':') != -1 || str.indexOf('/') != -1) {
			return "[" + str + "]";
		} else {
			return str;
		}
	}

	protected String protect(Object expression) {
		String str = expression.toString();
		if (str.indexOf(" ") != -1) {
			return "(" + str + ")";
		} else {
			return str;
		}
	}

}
